package com.fireline.beauty.seting;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

import com.fireline.beauty.jdbc.SqliteJdbcImpl;
import com.zgw.fireline.base.dataset.Dataset;
import com.zgw.fireline.base.frame.IFunction;
import com.zgw.fireline.base.widgets.Batch;
import com.zgw.fireline.base.widgets.BatchItem;

/**
 * 会员卡设置
 * */
public class HykEdit implements IFunction {
	public static final int Add = 1;
	public static final int Edit = 2;
	private Text textXmbh;
	private Text textDj;
	private Text textFwsj;
	private int type = 1; // 1 添加 2 修改
	public int resultCode = 0;

	/**
	 * 
	 * @param type
	 *            编辑类别 1新增 2修改
	 * */
	public HykEdit(int type, Dataset hykxx) {
		this.type = type;
		if (type == Edit) {
			hykSet.populate(hykxx, hykxx.getSelectedIndex());
			hykSet.setSelected(0);
		}
	}

	/**
	 * @wbp.nonvisual location=47,482
	 */
	private final Dataset hykSet = new Dataset(true, "hykxx",
			SqliteJdbcImpl.INSTANCE);
	/**
	 * @wbp.nonvisual location=223,482
	 */
	private final Batch addFfxm = new Batch(SqliteJdbcImpl.INSTANCE);
	/**
	 * @wbp.nonvisual location=113,482
	 */
	private final Batch editFfxm = new Batch(SqliteJdbcImpl.INSTANCE);
	private Label label_4;
	private Label label_5;
	private Control content;
	private Text text;
	private Text text_2;
	private Text text_1;

	/**
	 * @wbp.parser.entryPoint
	 */
	public Control createControl(Composite parent) {
		hykSet.setKeyColumns(new String[] {});

		BatchItem batchItem = new BatchItem(editFfxm);
		batchItem
				.setCommand("update hykxx set hykmc=?,knje=?,sj=? ,fwzk=?\r\n,cpzk=? ,bz=?\r\nwhere id=?");
		batchItem.setName("修改会员卡信息");

		BatchItem batchItem_1 = new BatchItem(addFfxm);
		batchItem_1
				.setCommand("insert into hykxx (hykmc,knje,sj ,fwzk,cpzk ,bz)\r\nvalues(?,?,?,?,?,?)");
		batchItem_1.setName("新增会员卡");
		final Composite content = new Composite(parent, SWT.NONE);
		content.setLayout(new GridLayout(1, false));

		Group composite = new Group(content, SWT.NONE);
		composite.setText("会员卡信息");
		GridLayout gl_composite = new GridLayout(2, false);
		gl_composite.verticalSpacing = 10;
		gl_composite.marginRight = 10;
		gl_composite.marginWidth = 15;
		gl_composite.marginHeight = 15;
		composite.setLayout(gl_composite);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false,
				1, 1));

		Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		lblNewLabel.setText("会员卡名称：");

		textXmbh = new Text(composite, SWT.BORDER);
		textXmbh.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));

		label_4 = new Label(composite, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_4.setText("卡内金额：");

		textDj = new Text(composite, SWT.BORDER);
		textDj.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1));

		label_5 = new Label(composite, SWT.NONE);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_5.setText("售价：");

		textFwsj = new Text(composite, SWT.BORDER);
		textFwsj.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));

		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_1.setText("服务折扣：");

		Composite composite_3 = new Composite(composite, SWT.NONE);
		composite_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));
		GridLayout gl_composite_3 = new GridLayout(2, false);
		gl_composite_3.marginHeight = 0;
		gl_composite_3.marginWidth = 0;
		composite_3.setLayout(gl_composite_3);

		text = new Text(composite_3, SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		text.setToolTipText("0.8 即为8折");

		Label lblNewLabel_1 = new Label(composite_3, SWT.NONE);
		lblNewLabel_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		lblNewLabel_1.setText("（0.8为8折）");

		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_2.setText("产品折扣：");

		Composite composite_4 = new Composite(composite, SWT.NONE);
		composite_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		GridLayout gl_composite_4 = new GridLayout(2, false);
		gl_composite_4.marginWidth = 0;
		gl_composite_4.marginHeight = 0;
		composite_4.setLayout(gl_composite_4);

		text_1 = new Text(composite_4, SWT.BORDER);
		text_1.setToolTipText("0.8 即为8折");
		text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1));

		Label label_6 = new Label(composite_4, SWT.NONE);
		label_6.setText("（0.8为8折）");
		label_6.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));

		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_3.setText("备注：");

		text_2 = new Text(composite, SWT.BORDER);
		text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1));

		Label label = new Label(content, SWT.SEPARATOR | SWT.HORIZONTAL);
		label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1,
				1));

		Composite composite_1 = new Composite(content, SWT.NONE);
		GridLayout gl_composite_1 = new GridLayout(1, false);
		composite_1.setLayout(gl_composite_1);
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));

		Composite composite_2 = new Composite(composite_1, SWT.NONE);
		composite_2.setLayout(new RowLayout(SWT.HORIZONTAL));
		composite_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true,
				false, 1, 1));

		Button btnSave = new Button(composite_2, SWT.NONE);
		btnSave.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doSave();
			}
		});
		btnSave.setLayoutData(new RowData(80, SWT.DEFAULT));
		btnSave.setText("保存&S");

		Button btnExit = new Button(composite_2, SWT.NONE);
		btnExit.setLayoutData(new RowData(80, SWT.DEFAULT));
		btnExit.setBounds(0, 0, 72, 22);
		btnExit.setText("退出&E");
		btnExit.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				resultCode = SWT.CANCEL;
				content.dispose();
			}
		});
		createGUIAfter();
		setParams();
		setValues();
		this.content = content;
		return content;
	}

	protected void doSave() {
		setParams();
		if (type == Edit) {
			editFfxm.execute();
			resultCode = SWT.OK;
			content.dispose();
		} else if (type == Add) {
			addFfxm.execute();
			resultCode = SWT.OK;
			content.dispose();
		}
	}

	public void clear() {

	}

	protected void setParams() {
		editFfxm.setParam(0, 0, textXmbh.getText());
		editFfxm.setParam(0, 1, textDj.getText());
		editFfxm.setParam(0, 2, textFwsj.getText());
		editFfxm.setParam(0, 3, text.getText());
		editFfxm.setParam(0, 4, text_1.getText());
		editFfxm.setParam(0, 5, text_2.getText());
		editFfxm.setParam(0, 6, hykSet.getValue("id"));
		addFfxm.setParam(0, 0, textXmbh.getText());
		addFfxm.setParam(0, 1, textDj.getText());
		addFfxm.setParam(0, 2, textFwsj.getText());
		addFfxm.setParam(0, 3, text.getText());
		addFfxm.setParam(0, 4, text_1.getText());
		addFfxm.setParam(0, 5, text_2.getText());
	}

	protected void setValues() {
		textXmbh.setText(hykSet.getValue("hykmc", String.class, ""));
		textDj.setText(hykSet.getValue("knje", String.class, ""));
		textFwsj.setText(hykSet.getValue("sj", String.class, ""));
		text.setText(hykSet.getValue("fwzk", String.class, ""));
		text_1.setText(hykSet.getValue("cpzk", String.class, ""));
		text_2.setText(hykSet.getValue("bz", String.class, ""));
	}

	protected void createGUIAfter() {
	}

}
